<?php
/**
 * 邮箱发送类
 *
 * @param $filename
 * @return array
 * @throws PHPExcel_Reader_Exception
 */
if (!function_exists('hxh_email_send')) {
    function hxh_email_send($to, $subject, $body, $path = null)
    {
        require_once dirname(__FILE__) . '/vendor/autoload.php';

        $config = [
            "charSet" => "utf8",
            "host" => "smtp.qq.com",
            "fromName" => "彗星号",
            "username" => "1024707033@qq.com",
            "from" => "1024707033@qq.com",
            "password" => "xdyflueftfopbcji",
            "SMTPSecure" => "ssl",
            "SMTPAuth" => true,
            "port" => 465,
        ];

        $mail = new PHPMailer\PHPMailer\PHPMailer();
        $mail->isSMTP();
        $mail->isHTML(true);
        $mail->CharSet = $config['charSet'];
        $mail->Host = $config['host'];
        $mail->SMTPAuth = $config['SMTPAuth'];
        $mail->FromName = $config['fromName'];
        $mail->Username = $config['username'];
        $mail->Password = $config['password'];
        $mail->SMTPSecure = $config['SMTPSecure'];
        $mail->Port = $config['port'];
        $mail->From = $config['from'];

        $mail->addAddress($to);
        if ($path) {
            $mail->addAttachment($path);
        }
        $mail->Subject = $subject;
        $mail->Body = $body;
        return $mail->send();
    }
}
